<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2024/1/3
  Time: 16:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<div style="text-align: center">
    <h2>北大青鸟合作供应商联系人</h2>
    <input type="text" name="cname" id="cname" style="margin-left: 150px">
    <select id="pid">
        <option value="0">—请选择—</option>
        <c:forEach items="${suppliers}" var="suppliers">
            <option value="${suppliers.id}">${suppliers.sname}</option>
        </c:forEach>
    </select>
    <input type="button" value="查询" onclick="onByPidNameList()">
    <a href="add.jsp" style="margin-left: 100px">添加供货商联系人</a>

    <table border="1" style="margin-left: 24%">
        <tr style="font-weight: bold;text-align: center">
            <td>供应商联系人编号</td>
            <td>供应商联系人姓名</td>
            <td>供应商联系人年龄</td>
            <td>供应商联系人手机</td>
            <td>所属供应商</td>
            <td>创建日期</td>
            <td>操作</td>
        </tr>

        <c:forEach items="${supplierContacts}" var="supplierContacts">
            <tr>
                <td>${supplierContacts.id}</td>
                <td>${supplierContacts.cname}</td>
                <td>${supplierContacts.age}</td>
                <td>${supplierContacts.mobile}</td>
                <td>${supplierContacts.sname}</td>
                <td>${supplierContacts.createdate}</td>
                <td><a href="javascript:void(0)" onclick="isDel(${supplierContacts.id})">删除</a></td>
            </tr>
        </c:forEach>
    </table>
</div>


<script src="js/jquery.js"></script>
<script>
    $(function () {
        $("tr:odd").css("background-color", "aqua")
        $("tr:even").css("background-color", "palegreen")
        $("tr:eq(0)").css("background-color", "#fff")
    })

    function onByPidNameList() {
        var cname = $("#cname").val()
        var pid = $("#pid").val()

        location.href = 'byPidNameList?cname=' + cname + '&pid=' + pid
    }

    function isDel(id) {
        if (confirm("确定要删除？")) {
            $.getJSON("del", {id: id}, function (data) {
                if (data > 0) {
                    alert("删除成功")
                    location.reload()
                } else {
                    alert("删除失败")
                }
            })
        }
    }
</script>

</body>
</html>
